﻿using System.Reflection;

namespace 燃油加注机指令翻译
{
    internal class HexMapper
    {
        public static void MapHexToClass<T>(string hexString, T obj)
        {
            Type type = typeof(T);
            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (property.GetCustomAttribute(typeof(HexMappingAttribute)) is HexMappingAttribute attribute)
                {
                    string hexValue = hexString.Substring(attribute.StartIndex, attribute.Length);
                    object value = Convert.ChangeType(hexValue, property.PropertyType);
                    property.SetValue(obj, value);
                }
            }
        }
    }
}
